package com.navinfo.platform.trip.analysis.service.impl.dongfeng;

import com.navinfo.location.mileage.bean.MileageAndFuel;
import com.navinfo.location.mileage.bean.Point;
import com.navinfo.location.mileage.calculation.Calculation;
import com.navinfo.platform.trip.common.annotation.SystemType;
import com.navinfo.platform.trip.common.enums.SystemTypeEnum;
import com.navinfo.platform.trip.analysis.service.MilAndFuelService;
import com.navinfo.platform.trip.common.pojo.PointProtocol;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 东风精准里程油耗服务
 */
@SystemType(value= SystemTypeEnum.DF, interfaceClass=MilAndFuelService.class )
public class MilAndFuelServiceImpl implements MilAndFuelService {
    @Override
    public MileageAndFuel calcMileageFuel(List<PointProtocol> points) {
        List<Point> pointList = points.stream().map(point -> {
            Point p = new Point();
            p.setTid(point.getTid());
            p.setGpsDate(point.getGpsTime());
            p.setRotation(point.getRotation());
            p.setGpsMileage(Optional.ofNullable(point.getGpsMileage()).orElse(0.0));
            p.setDiffMileage(Optional.ofNullable(point.getIntegralMileage()).orElse(0.0));
            p.setEcuMileage(Optional.ofNullable(point.getEcuMileage()).orElse(0.0));
            p.setMeterMileage(Optional.ofNullable(point.getMeterMileage()).orElse(0.0));
            p.setDiffFuelCons(Optional.ofNullable(point.getIntegralFuelCons()).orElse(0.0));
            p.setTotalFuelCons(Optional.ofNullable(point.getTotalFuelCons()).orElse(0.0));
            p.setSerialNumber(point.getSerialNumber());
            //东风需要设置acc状态
            p.setAcc(point.getAccStatus());
            return p;
        }).collect(Collectors.toList());

        return Calculation.getStdMilAndFuel4Df(pointList);
    }
}
